//
//  LCProductItem.m
//  stone-story
//
//  Created by dodo liu on 12-9-26.
//  Copyright (c) 2012年 liu dodo. All rights reserved.
//

#import "LCProductItem.h"
#import "UIImageView+WebCache.h"
@implementation LCProductItem
@synthesize delegate;
@synthesize button;
@synthesize imageview;
- (id)initWithFrame:(CGRect)frame productLogoString:(NSString*)urlStr productName:(NSString*)proname index:(int)index
{
    self = [super initWithFrame:frame];
    if (self) {
       /*
        UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [button setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"ZSPicHolder.png"]];
        [button setTag:2000+index];
        [self addSubview:button];
        */
        
        imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height-30)];
        [imageview setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"ZSPicHolder.png"]];
        [imageview setTag:5000+index];
        [self addSubview:imageview];
        
        UIView *infoBackView=[[UIView alloc]initWithFrame:CGRectMake(0, imageview.frame.size.height-40, imageview.frame.size.width, 40)];
        [infoBackView setBackgroundColor:[UIColor blackColor]];
        [infoBackView setAlpha:0.7];
        [imageview addSubview:infoBackView];
        
        UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(15,8,imageview.frame.size.width-15-15,25)] ;
        [label setFont:[UIFont fontWithName:@"Thonburi" size:13.0]];
        [label setTextColor:[UIColor whiteColor]];
        [label setNumberOfLines:1]; 
        [label setBackgroundColor:[UIColor clearColor]]; 
        [label setText:proname];
        [label setTextAlignment:UITextAlignmentCenter];
        [infoBackView addSubview:label];
        
         button=[[UIButton alloc]initWithFrame:CGRectMake(0, imageview.frame.origin.y+imageview.frame.size.height+5, imageview.frame.size.width,25)];
        //[button setBackgroundColor:[UIColor greenColor]];
        [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button setTitle:@"下 载" forState:UIControlStateNormal];
        [button.titleLabel setFont:[UIFont fontWithName:@"Thonburi" size:13.0]];
        [button setTag:2000+index];
        [self addSubview:button];
        
        //[self setActionBtnState:0];
        [self setTag:3000+index];

    }
    return self;
}

- (void)setActionBtnState:(int)flag
{
    switch (flag) {
        case 0:
        {[button setBackgroundImage:[UIImage imageNamed:@"btn_download_to_down.png"] forState:UIControlStateNormal]; 
            [button setTitle:@"下载" forState:UIControlStateNormal];
            break;}
        case 1:
        { [button setBackgroundImage:[UIImage imageNamed:@"btn_download_now_down.png"] forState:UIControlStateNormal];
             [button setTitle:@"正在下载..." forState:UIControlStateNormal];
            [button setEnabled:NO];
            break;}
        case 2:
        {  [button setBackgroundImage:[UIImage imageNamed:@"btn_download_have_down.png"] forState:UIControlStateNormal]; 
             [button setTitle:@"已下载" forState:UIControlStateNormal];
            [button setEnabled:NO];
            break;}
        default:
            break;
    }
}

-(void)click:(id)sender
{
    [delegate itemClick:sender:[sender tag]-2000];
}
/*

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
